#ifndef PAGER_H
#define PAGER_H

#include "inc.h"
#include "page.h"
#include "layout.h"

#define ALLOC_PAGES 50
// #define TEST_PAGE

typedef struct Pager {
    void *pgpool;       /* point to the page pool */
    uint16_t pgnums;
    uint8_t type;       /* belong what table type */
} pager_t;

void printPageLayout(page_t *page);
pager_t *createPager(int type);
void destroyPager(pager_t *pager);
int getPage(pager_t *pager, page_t *page);
void cleanPage(page_t *page);
int insertRecordToPage(page_t *page, record_t *record);
int deleteRecordfromPage(page_t *page, uint16_t index);
char *getRecordFromPage(page_t *page, uint16_t index);
int flushPageToDisk(page_t *page, FILE *file);
int loadPageFromDisk(page_t *page, FILE *file);
int serialize(record_t *src, char *dest);
int deserialize(char *src, record_t *dest);

#ifdef TEST_PAGE
int allocPages(pager_t *pager, uint16_t page_nums);
void freePages(pager_t *pager);
int isEnoughMem(page_t *page);
#endif  /* TEST_PAGE */

#endif  /* PAGER_H */